package com.core.app;

import org.springframework.beans.factory.annotation.Autowired;

import com.core.app.window.view.AdminView;
import com.core.app.window.view.HomeView;
import com.core.app.window.view.LoginView;
import com.core.context.Inject;
import com.core.service.SekolahService;
import com.vaadin.Application;
import com.vaadin.ui.Window;

/**
 * Main Application class
 * @author yanuar
 *
 */
public class CoreApplication extends Application {

	@Autowired
	private SekolahService sekolahService;

	private static final long serialVersionUID = 2048826915437705599L;
	private Window mainWindow;
	private HomeView homeView;
	private AdminView adminView;
	private LoginView loginView;

	/**
	 * First hit method!
	 */
	@Override
	public void init() {

		Inject.Inject(this);

		mainWindow = new Window();
		setMainWindow(mainWindow);

		showHomeView();
		setTheme("sips-theme");
	}

	public void showHomeView() {
		homeView = new HomeView(this);
		mainWindow.setContent(homeView);
	}

	public void showLoginView() {
		loginView = new LoginView(this);
		mainWindow.setContent(loginView);
	}

	public void showAdminView() {
		if (getUser() == null) {
			showLoginView();
		} else {
			adminView = new AdminView(this);
			mainWindow.setContent(adminView);
		}
	}
	
	public void logout(){
		if(getUser()!=null){
			setUser(null);
		}
		
		showHomeView();
	}

}
